CMAKE_MINIMUM_REQUIRED(VERSION 3.6)
PROJECT(GeeJoanKV)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Installation directory" FORCE)
message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
set(GEEJOAN_OUTPUTDIR ${CMAKE_SOURCE_DIR}/${CMAKE_SYSTEM_NAME}.out)
# 是否编译持久化功能 , 默认支持
option(KV_PERSISTENT_SUPPORT "Support persistent operation" ON)

#编译 动态库
option(BUILD_SHARED_LIBS "Build SHARD" ON)
include_directories()
set(KV_CPP_SRC Tool/KeyValueBase.cpp)
function(find_threads)
    set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
    find_package(Threads)
    if (Threads_FOUND)
        add_definitions(-DHAVE_PTHREAD)
    endif ()
endfunction()

#add_definitions(-DFILE_PERSISTENNCE_ENABLE)
if (KV_PERSISTENT_SUPPORT)
    MESSAGE(STATUS "enable File")
    add_definitions(-DFILE_PERSISTENNCE_ENABLE)
    find_threads()
    set(protobuf_source_dir libs/protobuf_lite)
    include(libs/protobuf_lite/libprotobuf-lite.cmake)
    include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
    set(KV_CPP_SRC
            ${KV_CPP_SRC}
            Tool/KeyValueDataTypeSerialize.pb.cc
            ${libprotobuf_lite_files}
            ${libprotobuf_lite_includes}
            )
else ()
    MESSAGE(STATUS "disenable File")
endif ()
if (BUILD_SHARED_LIBS)
    add_library(${PROJECT_NAME}_s SHARED ${KV_CPP_SRC})
endif ()
add_library(${PROJECT_NAME} STATIC ${KV_CPP_SRC})


add_executable(testKeyValue testKeyValue.cpp)
target_link_libraries(testKeyValue ${PROJECT_NAME})
if (KV_PERSISTENT_SUPPORT)
    add_executable(testSerial testSerial.cpp)
    target_link_libraries(testSerial ${PROJECT_NAME})

    add_executable(testSerial100k testSerial100k.cpp)
    target_link_libraries(testSerial100k ${PROJECT_NAME})
endif ()

install(TARGETS
        ${PROJECT_NAME}
        testSerial100k
        testSerial
        testKeyValue
        EXPORT GeeJoanKV-targets
        RUNTIME DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoanKV/bin
        LIBRARY DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoanKV/libs
        ARCHIVE DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoanKV/libs
        )
INSTALL(FILES
        ${CMAKE_SOURCE_DIR}/Tool/KeyValueDataType.h
        ${CMAKE_SOURCE_DIR}/Tool/KeyValueBase.h
        DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoanKV/include/Tool)